package com.rw.utils;

import com.rw.dao.UserDao;
import com.rw.pojo.User;
import com.sun.tools.doclets.formats.html.SourceToHTMLConverter;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.applet.AppletContext;
import java.sql.*;

/**
 * @author rabit
 */
public class JDBCUtils {
    public static void main1(String[] args) throws ClassNotFoundException, SQLException {
        ApplicationContext ac = new ClassPathXmlApplicationContext("applicationcontext.xml");
        DataSource dataSource = (DataSource) ac.getBean("dataSource");
        String sql = "select uid,uname,pwd from t_user";
        ResultSet resultSet = dataSource.selectData(sql);
        User user = new User();
        while (resultSet.next()){
            user.setUid(resultSet.getInt("uid"));
            user.setUname(resultSet.getString("uname"));
            user.setPwd(resultSet.getString("pwd"));
            System.out.println(user);
        }
    }

    public static void main(String[] args) throws SQLException {
        ApplicationContext ac = new ClassPathXmlApplicationContext("applicationcontext.xml");
        UserDao userDao = (UserDao) ac.getBean("userDao");
        User user = userDao.login("张三","123");
        System.out.println(user);
    }
}
